package com.ruoyi.web.ydz.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.ydz.domain.DistrictBase;
import com.ruoyi.web.ydz.domain.UserDocument;
import com.ruoyi.web.ydz.service.IDistrictBaseService;
import com.ruoyi.web.ydz.service.IUserDocumentService;
import com.ruoyi.web.ydz.util.websocket.WebSocketUsers;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 用户个人资料Controller
 * 
 * @author ruoyi
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/ydz/document")
public class UserDocumentController extends BaseController
{
    @Resource
    private IUserDocumentService userDocumentService;

    @Resource
    private IDistrictBaseService districtBaseService;

    /**
     * 查询用户个人资料列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:document:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserDocument userDocument)
    {
        startPage();
        List<UserDocument> list = userDocumentService.selectUserDocumentList(userDocument);
        return getDataTable(list);
    }

    /**
     * 导出用户个人资料列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:document:export')")
    @Log(title = "用户个人资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserDocument userDocument)
    {
        List<UserDocument> list = userDocumentService.selectUserDocumentList(userDocument);
        ExcelUtil<UserDocument> util = new ExcelUtil<UserDocument>(UserDocument.class);
        util.exportExcel(response, list, "用户个人资料数据");
    }

    /**
     * 获取用户个人资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('ydz:document:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userDocumentService.selectUserDocumentById(id));
    }

    /**
     * 新增用户个人资料
     */
    @Log(title = "用户个人资料", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody UserDocument userDocument)
    {
        return toAjax(userDocumentService.insertUserDocument(userDocument));
    }

    /**
     * 修改用户个人资料
     */
    @PreAuthorize("@ss.hasPermi('ydz:document:edit')")
    @Log(title = "用户个人资料", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    public AjaxResult edit(@RequestBody UserDocument userDocument)
    {
        return toAjax(userDocumentService.updateUserDocument(userDocument));
    }

    /**
     * 删除用户个人资料
     */
    @PreAuthorize("@ss.hasPermi('ydz:document:remove')")
    @Log(title = "用户个人资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userDocumentService.deleteUserDocumentByIds(ids));
    }

    /*获取中国省市列表*/
    @RequestMapping("/getAreas")
    public TableDataInfo getAreas(){
        startPage();
        List<DistrictBase> districtBases = districtBaseService.selectDistrictBaseList(new DistrictBase());
        return getDataTable(districtBases);
    }

    /*发信息测试版*/
    @RequestMapping("/textmessage")
    public void sendMessageToUser(String userId, String message){
        WebSocketUsers.sendMessageToUser(userId,message);
    }
}
